fix(@angular/build): prevent esbuild service child process leakage#33267
Conversation
There was a problem hiding this comment.
Code Review
This pull request wraps the watcher setup and initial build result emission in a try-finally block to ensure that the build result is disposed of when not in watch mode. It also simplifies the bundler context by always creating and rebuilding an esbuild context instead of branching for non-incremental builds. A review comment identifies a potential resource leak if an error occurs during the initial emit or watcher setup when watch mode is enabled, as the current finally block only disposes of the result if watch mode is disabled. A suggestion is provided to track whether the generator successfully transitions to the watch loop and clean up resources accordingly.
Use scoped esbuild.context() for single builds to guarantee accurate tracking and clean disposal of all internal esbuild service child processes. Additionally, wrap runEsBuildBuildAction in a try/finally block leveraging a state tracking flag to deterministically trigger context disposal for all single builds and watch initialization failure paths. This leakage primarily impacts programmatic usage and custom Architect decorators, where the hosting Node.js process remains alive after build completion. Fixes angular#33201
81d0675 to
2d9b166
Compare
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Use scoped esbuild.context() for single builds to guarantee accurate tracking and clean disposal of all internal esbuild service child processes. Additionally, wrap runEsBuildBuildAction in a try/finally block to deterministically trigger context disposal when a single build finishes or encounters an error.
This leakage primarily impacts programmatic usage and custom Architect decorators, where the hosting Node.js process remains alive after build completion.
Fixes #33201
REVIEWER NOTE: Use "Hide whitespace"